import { _decorator, Component, Label, Node } from 'cc';
import { Rank, RankOper } from '../entity/Rank';
import { UIManager } from '../common/UIManager';
import RankApi from '../api/RankApi';
import { PrefabEnum } from '../common/PrefabEnum';
import { RankDetail } from '../rank/RankDetail';
import ReportApi from '../api/ReportApi';
import { Report } from '../entity/Report';
import { FightManager } from '../fight/FightManager';
import { ReportFight } from '../report/ReportFight';
const { ccclass, property } = _decorator;

@ccclass('PVPItem')
export class PVPItem extends Component {
    @property(Label)
    index:Label
    @property(Label)
    playerName:Label
    @property(Label)
    union:Label
    @property(Node)
    fight:Node

    private rank:Rank

    start() {
        this.node.on(Node.EventType.TOUCH_END, this.onTouch, this)
        this.fight.on(Node.EventType.TOUCH_END, this.onFight, this)
    }

    setData(rank:Rank){
        this.rank = rank
        this.index.string = rank.HeroRank + ''
        this.playerName.string = rank.PlayerName
        this.union.string = rank.AllyName
    }

    async onTouch(){
      
        let ui = await UIManager.instance.openUI(PrefabEnum.RankDetail)
        ui.getComponent(RankDetail).setData(this.rank.PlayerId)
    }

    async onFight(){
       
        let params = {
            oper: RankOper.Hero,
          
            pvp: this.rank.PlayerId
        }
        await UIManager.instance.showLoading()
        let res = await RankApi.Execute(params)
        console.log(res)
        res = await ReportApi.execute({id:res.data.sn})
        console.log(res)
        UIManager.instance.closeLoading()

        let ui = await UIManager.instance.openUI(PrefabEnum.ReportFight)
        ui.getComponent(ReportFight).setData(res.data)

        return 
        let report:Report = res.data
        FightManager.instance.report = report
        UIManager.instance.loadScene('fight')
    }   
}


